/**
 * @File AccountingSetupDaoImpl.java


 * @author Agam Bhamra
 * @Version 1.0
 * @Date July 31, 2013
 * 
 * Copyright (c) 2011 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproducuce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package in.ac.dei.edrp.generalLedger.accountingSetup;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Component;

import com.ibatis.sqlmap.client.SqlMapClient;


@Component
@Qualifier("AccountingSetupDaoImpl")

public class AccountingSetupDaoImpl extends SqlMapClientDaoSupport implements AccountingSetupDao {
	
	private static Logger logObj = Logger.getLogger(AccountingSetupDaoImpl.class);
	
	public AccountingSetupDaoImpl() {}
	@Autowired
	
	public AccountingSetupDaoImpl(SqlMapClient sqlMapClient)
	{
		setSqlMapClient(sqlMapClient);
	}
	
	public String addLegalEntity(AccountingSetupInfoBean input)
	{
		String status = "";
		try 
		{
			getSqlMapClientTemplate().insert("accountingSetup.addLegalEntity", input);
			status="done";
		} 
		catch (Exception e)
		{
			logObj.info("Exception in adding legal entity  - addLegalEntity method");
			logObj.error(e);
			System.out.println("Error in addLegalEntity:                 \nStart\n"+e+"\nend\n");
			status = e.getClass().toString();
		}
		return status;
	}
	
	public List<AccountingSetupInfoBean> getLegalEntities()
	{
		List<AccountingSetupInfoBean> legalEntities = null;
		try {
			legalEntities = getSqlMapClientTemplate().queryForList("accountingSetup.getLegalEntities");
		} catch (Exception e) {
			logObj.info("Exception in getting legal entities  - getLegalEntities method");
			logObj.error(e);
			System.out.println("Error in getLegalEntities:                 \nStart\n"+e+"\nend\n");
		}
		return legalEntities;
	}
	
	public List<AccountingSetupInfoBean> getChartOfAccounts()
	{
		List<AccountingSetupInfoBean> chartOfAccounts = null;
		try {
			chartOfAccounts = getSqlMapClientTemplate().queryForList("accountingSetup.getChartOfAccounts");
		} catch (Exception e) {
			logObj.info("Exception in getting chart of accounts  - getChartOfAccounts method");
			logObj.error(e);
			System.out.println("Error in getChartOfAccounts:                 \nStart\n"+e+"\nend\n");
		}
		return chartOfAccounts;
	}
	
	public List<AccountingSetupInfoBean> getAccountingCalendar()
	{
		List<AccountingSetupInfoBean> accountingCalendar = null;
		try {
			accountingCalendar = getSqlMapClientTemplate().queryForList("accountingSetup.getAccountingCalendar");
		} catch (Exception e) {
			logObj.info("Exception in getting Accounting Calendars  - getAccountingCalendar method");
			logObj.error(e);
			System.out.println("Error in getAccountingCalendar:                 \nStart\n"+e+"\nend\n");
		}
		return accountingCalendar;
	}
	
	public List<AccountingSetupInfoBean> getCurrency()
	{
		List<AccountingSetupInfoBean> currency = null;
		try {
			currency = getSqlMapClientTemplate().queryForList("accountingSetup.getCurrency");
		} catch (Exception e) {
			logObj.info("Exception in getting Currencies  - getCurrency method");
			logObj.error(e);
			System.out.println("Error in getCurrency:                 \nStart\n"+e+"\nend\n");
		}
		return currency;
	}
	
	public String saveAccoutingSetup(AccountingSetupInfoBean input)
	{
		String status = "";
		try 
		{
			getSqlMapClientTemplate().insert("accountingSetup.saveAccoutingSetup", input);
			status="done";
		} 
		catch (Exception e)
		{
			logObj.info("Exception in saving Accounting Setup  - saveAccoutingSetup method");
			logObj.error(e);
			System.out.println("Error in addLegalEntity:                 \nStart\n"+e+"\nend\n");
			status = e.getClass().toString();
		}
		return status;
	}
	
	public List<AccountingSetupInfoBean> getLedgers()
	{
		List<AccountingSetupInfoBean> ledgers = null;
		try {
			ledgers = getSqlMapClientTemplate().queryForList("accountingSetup.getLedgers");
		} catch (Exception e) {
			logObj.info("Exception in getting Ledgers  - getLedgers method");
			logObj.error(e);
			System.out.println("Error in getLedgers:                 \nStart\n"+e+"\nend\n");
		}
		return ledgers;
	}

}
